package com.oystertech.sportcms.controller;

import com.oystertech.sportcms.common.result.Result;
import com.oystertech.sportcms.model.vo.UserInfoVO;
import com.oystertech.sportcms.service.StatisticsService;
import com.oystertech.sportcms.service.SysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 统计接口
 *
 * @author Oyster Cheung
 * @version 2023-09-21
 * @since 2023-09-21
 */
@Tag(name = "统计接口")
@RestController
@RequestMapping("/api/v2/statistics")
@RequiredArgsConstructor
public class StatisticsController {
	private final StatisticsService statisticsService;
	private final SysUserService userService;

	@Operation(summary = "统计当前用户运动员总数", security = {@SecurityRequirement(name = "Authorization")})
	@GetMapping("/athleteByTeam")
	public Result countAthleteByTeam() {
		UserInfoVO userInfoVO = userService.getUserLoginInfo();
		List<Long> teamIds = userInfoVO.getTeamIds();
		return Result.success(statisticsService.countAthleteByTeam(teamIds));
	}
}
